<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-input v-model="chapterName" clearable placeholder="输入章节名称搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-input v-model="courseName" clearable placeholder="输入课程名称搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-input v-model="userName" clearable placeholder="输入学员姓名搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="init">搜索</el-button>
    </div>
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="60">
      </el-table-column>
      <el-table-column prop="userName" label="学员姓名" width="100" align="center"/>
      <el-table-column prop="chapterName" label="章节名称" width="200" align="center"/>
      <el-table-column prop="courseName" label="课程名称" width="200" align="center"/>
      <el-table-column prop="noteContent" label="笔记内容" :show-overflow-tooltip='true' align="center"/>
      <el-table-column prop="createTime" label="创建时间" width="200" align="center"/>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-popover
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定
              </el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
  import { del } from '@/api/business/note'
  import initData from '@/mixins/initData'

  export default {
    mixins: [initData],
    data() {
      return {
        loading: false,
        delLoading: false,
        userName: '',
        chapterName: '',
        courseName: ''
      }
    },
    created() {
      this.$nextTick(() => {
        this.init()
      })
    },
    methods: {
      beforeInit() {
        this.url = 'web/note/page-list'
        this.params = {
          page: this.page,
          size: this.size,
          courseName: this.courseName,
          chapterName: this.chapterName,
          userName: this.userName
        }
        return true
      },
      subDelete(id) {
        this.delLoading = true
        del(id).then(res => {
          this.$notify({
            title: '删除成功',
            type: 'success',
            duration: 2500
          })
          this.init()
        })
        this.delLoading = false
        this.$refs[id].doClose()
      }
    }
  }
</script>
